package com.icss.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author safe
 * @create 2022-08-31 13:22
 * @introduction
 */
@Service
public class LogisticsService {
    public String logisticSuccess(Integer id){
        return "success " + id;
    }

    // 服务提供者的 服务熔断
    @HystrixCommand(fallbackMethod = "timeout",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value="3000")
    })
    public String logisticTimeout(Integer id){
        try {
            TimeUnit.SECONDS.sleep(8);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "timeout " + id;
    }

    // 熔断方法
    public String timeout(Integer id){
        return "服务提供者 logisticTimeout 方法的服务熔断 " + id;
    }

}
